home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / nShell-Pro.sit / nShell-Pro / doc / nShell™ User's Guide.rsrc / TEXT_136.txt < prev    next >
Text File  |  1994-12-27  |  3KB  |  64 lines

  1.  
  2. Flow Of Control
  3.  
  4. Flow of Control statements, available in nShell-Pro(tm) control when and how other statements are executed.  That is, they control the flow of execution through a command line or through a script file.
  5.  
  6. When flow of control structures are typed into the command line, they must start and end within the same line:
  7.  
  8. if yesno "ready?" then hello endif
  9.  
  10. When flow of control structures are used in scripts, they may be broken into several lines:
  11.  
  12. if yesno "ready?"
  13. then
  14.     hello
  15. endif
  16.  
  17. if then else
  18.  
  19. This structure has the following form:
  20.  
  21. if <commands1> then <commands2> [else <commands3>] endif
  22.  
  23. If the result of the last command of the set <commands1> completes without error (result = zero), then the <commands2> clause will be executed.
  24.  
  25. If the result of the last command of the set <commands1> produces an error (result <> zero), and an else-clause is present, that clause will execute.
  26.  
  27. while do done
  28.  
  29. This structure has the following form:
  30.  
  31. while <commands1> do <commands2> done
  32.  
  33. In this structure, the <commands1> clause will always execute.  If the result of the last command of the set completes without error (result = zero), then the <commands2> clause will be executed.  Control will then return to the <commands1> clause, and the process will continue until the last command of this set produces an error (result <> 0).
  34.  
  35. until do done
  36.  
  37. This structure has the following form:
  38.  
  39. until <commands1> do <commands2> done
  40.  
  41. In this structure, the <commands1> clause will always execute.  If the result of the last command of the set produces an error (result <> zero), then the <commands2> clause will be executed.  Control will then return to the <commands1> clause, and the process will continue until the last command of this set completes without error (result = 0).
  42.  
  43. Testing Conditions
  44.  
  45. A number of commands are included in this release to test conditions.  The commands below produce a successful result (zero) when the listed condition is true:
  46.  
  47.     .eq.    Equal
  48.     .ne.    Not Equal
  49.     .gt.    Greater Than
  50.     .lt.    Less Than
  51.     .ge.    Greater Than or Equal To
  52.     .le.    Less Than or Equal To
  53.  
  54. These operators are used to compare two parameters.  If both parameters are legal integers, an integer comparison is performed.  If one or both parameters are not integers, a string comparison is performed.
  55.  
  56. These comparison commands may be used to test the return value from a previous command.  It is important to note, however, that the comparison itself produces a return value and will overwrite "$?".  For this reason, the return code should be saved into a temporary variable before a series of comparisons are performed:
  57.  
  58. command_x
  59. set temp $?    # save the result
  60. if .lt. $temp 0 then echo "A serious error has occurred." endif
  61. if .eq. $temp 0 then echo "Everything is ok" endif
  62. if .gt. $temp 0 then echo "command_x returned a value of $temp" endif
  63.  
  64.